var arrayPairSum = function(nums) {
    const n = nums.length;
    nums.sort((a,b) => a-b)
    let sum = 0;
    for(let i = 0; i <n;) {
        sum+=nums[i]
        i=i+2;
    }
    return sum;
};
console.log(arrayPairSum([4,3,1,2]))